// shoppingCartbalance.js
var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        indexs: 0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        console.log(options)
        var that = this;
        that.setData({
            shopCarArray: options.shopCarArray
        })

        wx.request({
            url: app.data.baseUrl + '/AibraUsb/shopCar/shopping.do',
            data: {
                openId: app.globalData.openid,
                shopCarArray: that.data.shopCarArray
            },
            success: function(res) {
                var Allprice = 0;
                var AllPoints = 0;
                for (var i = 0; i < res.data.shopCarList.length; i++) {
                    Allprice += (res.data.shopCarList[i][5] * 1) * (res.data.shopCarList[i][4] * 1);
                    AllPoints += res.data.shopCarList[i][5] * res.data.shopCarList[i][7]
                }

                var ucList = res.data.ucList;
                var ucLists = []
                for (var j = 0; j < ucList.length; j++) {
                    ucLists[j] = "优惠券" + ucList[j][1] + "元"
                }
                that.setData({
                    shopCarList: res.data.shopCarList,
                    addressList: res.data.addressList,
                    userCouponArray: res.data.userCouponArray,
                    money: res.data.money,
                    totalPoints: res.data.totalPoints,
                    ucList: res.data.ucList,
                    ucLists: ucLists,
                    Allprice: Allprice,
                    AllPoints: AllPoints
                })

            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    },
    bindAddress: function() {
        wx.navigateTo({
            url: '../../deliveryAddress/deliveryAddress'
        })
    },
    WxPay: function() {
        var that = this;

        console.log(app.globalData.openid)
        wx.request({
            url: app.data.baseUrl + '/AibraUsb/orders/shoppingPay.do',
            data: {
                shopCarArray: that.data.shopCarArray,
                userCouponArray: 2,
                openId: app.globalData.openid,
                addressId: that.data.addressList[0][0]
            },
            success: function(res) {
                console.log(res)
                wx.requestPayment({
                    timeStamp: res.data.timeStamp,
                    nonceStr: res.data.nonceStr,
                    package: res.data.package,
                    signType: res.data.signType,
                    paySign: res.data.paySign,

                    agent: res.data.agent,
                    appId: res.data.appId,
                    packageValue: res.data.packageValue,
                    sendUrl: res.data.sendUrl,
                    success: function(res) {
                        console.log(res)
                    }
                })

            }

        })
    },
    bindPickerChange: function(e) {
        var that = this;
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            id: e.detail.value
        })
    },
})